export default {
	data() {
		return {
			statusList: [
                // { id: '', name: '全部' },
				{ id: '0', name: '禁用' },
				{ id: '1', name: '启用' }
			]
		}
	},
	methods: {
		changeStatus(row, fn) {
            // console.log('row', row)
            // return
			const params = {
				id: row.id,
				status: row.status
			}
			fn(params).then(res => {
				if (res.err_code === 0) {
					this.$message.success('操作成功')
				} else {
					this.$message.error(res.err_msg)
				}
			})
		},
		switchStatus(row, fn, statusKey = 'status') {
			let params = {
				id: row.id,
				[statusKey]: row[statusKey]
			}
			fn(params)
				.then(res => {
					this.$message.success(res.err_msg)
				})
				.catch(_ => {
					row[statusKey] = Number(!row[statusKey])
				})
		},
		deleteItem(row, fn, fnArgs) {
			this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
				type: 'warning'
			}).then(() => {
				const params = {
					id: row.id,
                    status: -1
				}
				fn(params).then(res => {
					if (res.err_code === 0) {
						this.$message.success('删除成功')
						if (fnArgs) {
                            this.getPageData(fnArgs)
                        } else {
                            this.getPageData()
                        }
					} else {
						this.$message.error(res.err_msg)
					}
				})
			})
		},
		deleteSelectedItem(rows, fn) {
			this.$confirm('此操作将删除选中的数据，是否继续？', '提示', {
				type: 'warning'
			}).then(() => {
				const params = {
					id: rows.join(',')
				}
				fn(params).then(res => {
					if (res.err_code === 0) {
						this.$message.success('删除成功')
						this.getPageData()
					} else {
						this.$message.error(res.err_msg)
					}
				})
			})
		}
	}
}
